package com.kim.store.contorller;

import com.kim.store.entity.Order;
import com.kim.store.service.IOrderService;
import com.kim.store.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/order")
public class OrderController extends BaseController{
    @Autowired
    private IOrderService orderService;

    @RequestMapping("/create")
    public JsonResult<Order> create(Integer aid, HttpSession session, Integer[] cids){
        Order order = orderService.create(aid, getUidFromSession(session),
                                    getUsernameFromSession(session), cids);
        return new JsonResult<>(OK,order);
    }

    @RequestMapping("/create_now")
    public JsonResult<Order> createNow(Integer aid, @RequestParam("id") Integer pid , HttpSession session){
        Order order = orderService.createNow(aid, getUidFromSession(session),
                         pid,getUsernameFromSession(session));
        return new JsonResult<>(OK,order);
    }
}
